import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        hasLogin: false,
        token: "",
        userInfo: {},
		companyInfo:{},
        indexInfo: {},
        adress: "",
        shareid: "",
        companyId: "",
		bindCompanyId:"",
        storeId: "",
        code: "",
        codelist: "",
        custId: "",
        custList: [],
        openId: ""
    },
    mutations: {
        getadress(state, data) {
            state.adress = data
        },
        changeStore(state, data) {
            state.storeId = data
        },
        changShareid(state, data) {
            state.shareid = data;
            uni.setStorage({ //缓存用户登陆状态
                key: 'shareid',
                data: data
            })
        },
        changCompanyId(state, data) {
            state.companyId = data;
            uni.setStorage({ //缓存用户登陆状态
                key: 'companyId',
                data: data
            })
        },
		changbindCompanyId(state, data) {
			console.log(data)
		    state.bindCompanyId = data;
		    uni.setStorage({ //缓存用户登陆状态
		        key: 'bindCompanyId',
		        data: data
		    })
		},
        changIndex(state, data) {
            state.indexInfo = data
        },
		changeCompany(state,data){
			state.companyInfo = data
		},
		changeperson(state,type){
			Vue.prototype.$ComFunJS.ajax({
				url: "/rest/api/getUserInfo",
				method: 'get',
				success: function(res) {
					if (res.code==0) {
						state.userInfo = res.data;
					}
				}
			})				
		},			
        login(state, provider) {
            let token = provider
            state.hasLogin = true;
            state.token = token;
            Vue.prototype.$ComFunJS.token = token;
            uni.setStorage({ //缓存用户登陆状态
                key: 'token',
                data: token
            })
        },
        logout(state) {
            state.hasLogin = false;
            state.token = "";
            state.userInfo = {};
            uni.removeStorage({
                key: 'token'
            });
            Vue.prototype.$ComFunJS.token = "";
        }
    },
    actions: {

    }
})

export default store
